#include "common.hpp"
#include "fifo.hpp"
int main()
{
    // 检查获取key值是否出错
    int key = GetKey();
    cout << ToHex(key) << endl;

    // 获取shmid
    int shmid = GetShm(defaultsize);
    cout << shmid << endl;

    // 进程与shm挂接
    char *buffer = (char *)SetRelationship(shmid);

    // 进程间通信  这里借用管道的同步互斥机制，当写端终止写入或关闭，读端读到0，
    Sync syn;
    syn.OpenWrite();

    for (char c = 'A'; c < 'H'; c++)
    {
        buffer[c - 'A'] = c;
        sleep(1);
        syn.wakeup();//当读端不再读，OS会强制关闭该管道并释放信号杀死该进程
    }
    // 写端不再写，读端会返回0

    // 解除挂接
    RemoveRelationship(buffer);
    return 0;
}